package com.micro.monitoring.basic;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.micro.monitoring.util.Communicate;


public abstract class BasicFragment extends Fragment implements View.OnClickListener{

    private View rootView;
    public Communicate bCallback;
    private Fragment fragment;
    private Bundle savedInstanceState;

    public Bundle getSavedInstanceState() {
        return savedInstanceState;
    }

    public BasicFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = LayoutInflater.from(getActivity()).inflate(getContentView(), null);
        this.savedInstanceState=savedInstanceState;
        initView(rootView);
        setListener();
        getData();
        initData();
        return rootView;
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        fragment=getFragment();
        if(fragment!=null){
            bCallback=(Communicate) fragment;
        }
    }

    /**
     * 解析子类的布局
     *
     * @return
     */
    protected abstract int getContentView();

    protected abstract Fragment getFragment();

    /**
     * 初始化子类的布局
     *
     * @param rootView
     */
    protected abstract void initView(View rootView);

    /**
     * 设置子类的OnClickListener事件
     */
    protected abstract void setListener();

    /**
     * 子类获取对象
     * 一、获取网络请求
     * 二、获取传递的数据
     */
    protected abstract void getData();

    /**
     * 子类对象赋值
     * 网络请求或者是传递的数据赋值
     */
    protected abstract void initData();
//    /**
//     * @description 检查drawable是否为空 空的话就调用错误提示框重新拍照
//     * @param
//     * @return
//     * @author Kudrat
//     * @time 2021/10/30 12:40
//     */
//    public boolean checkNullDrawable(Drawable drawable){
//        if(drawable==null){
//            bCallback.showDialogId(Constant.HTTP_FAIL);
//            return false;
//        }
//        return true;
//    }
}